package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.ClothesKindRequest;
import com.example.saiweisi.controller.request.NewsRequest;
import com.example.saiweisi.controller.request.PageBaseRequest;
import com.example.saiweisi.model.ClothesKind;
import com.example.saiweisi.model.News;
import com.example.saiweisi.service.interf.INewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/news")
@RestController
@CrossOrigin
@Slf4j
public class NewsController {
    @Resource
    private INewsService newsService;
    /**
     * 查询所有的新闻
     * @return 返回json
     */
    @GetMapping("/getall")
    public Result getall() {
        return Result.success(newsService.getall());
    }
    //分页查询所有新闻
    @GetMapping("/page")
    public Result page(NewsRequest newsRequest  ) {
        return Result.success(newsService.page(newsRequest));
    }
    //添加新闻
    @PostMapping("/add")
    public Result addnews(@RequestBody News news){
        newsService.addnews(news);
        return Result.success("添加成功");
    }
    //删除新闻
    @DeleteMapping("/delete/{newsId}")
    public Result deletenews(@PathVariable Long newsId){
        newsService.deletenews(newsId);
        return Result.success("删除成功");
    }
    //根据id查找新闻
    @GetMapping("/getbyid/{newsId}")
    public Result getById(@PathVariable Long newsId){
        News news=newsService.getById(newsId);
        return Result.success(news);
    }
    //修改新闻
    @PutMapping("/update")
    public Result updatenews(@RequestBody News news){
        newsService.updatenews(news);
        return Result.success("修改成功");
    }
}
